﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
namespace ef.SQLServerProvider
{
    public class UserBaseRepository : DataBase.DataBase, DataProvider.IUserBaseRepository
    {
        #region IUserBaseRepository 成员

        public void Insert(Entity.UserBase_Ext entity)
        {
            base.Insert<Entity.UserBase>(entity.UserBase);
            base.Insert<Entity.UserInfo>(entity.UserInfo);
        }

        public void update(Entity.UserBase_Ext entity)
        {
            base.Update<Entity.UserBase>(entity.UserBase);
            base.Update<Entity.UserInfo>(entity.UserInfo);
        }

        public void delete(Entity.UserBase_Ext entity)
        {
            base.Delete<Entity.UserInfo>(entity.UserInfo);
            base.Delete<Entity.UserBase>(entity.UserBase);

        }

        public IQueryable<Entity.UserBase_Ext> GetModel()
        {
            var linq = from data in base.GetModel<UserBase>()
                       join data2 in base.GetModel<User_Diary>() on data.ID equals data2.UserBase_ID into list
                       join data3 in base.GetModel<UserInfo>() on data.ID equals data3.ID
                       select new UserBase_Ext
                       {
                           UserBase = data,
                           User_Diary = list.AsEnumerable(),
                           UserInfo = data3,
                       };
            return linq.OrderBy(i=>i.UserBase.ID);
        }

        #endregion
    }
}
